<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/testtask' }"
        >测试任务</el-breadcrumb-item
      >
      <el-breadcrumb-item>测试结果</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card style="margin-top: 10px">
      <!-- 测试用例列表区域 -->
      <el-table :data="testresultList" border stripe>
        <el-table-column label="项目" prop="epic"> </el-table-column>
        <el-table-column label="模块" prop="feature">
          <!-- <template slot-scope="scope">
            <span v-if="scope.row.result == 'pending'">
            </span>
          </template> -->
        </el-table-column>
        <el-table-column label="子模块" prop="story"></el-table-column>
        <el-table-column label="测试用例标题" prop="name"></el-table-column>
        <el-table-column label="测试用例编号" prop="suite"></el-table-column>
        <el-table-column label="执行结果" prop="status"></el-table-column>
        <el-table-column label="开始时间" prop="start">
            <!-- <template slot-scope="scope">
            {{this.$moment(Number(scope.row.start).format('HH-MM-DD'))   }}
          </template> -->
        </el-table-column>
        <el-table-column label="执行时长" prop="duration"></el-table-column>
        <el-table-column label="分析结果" prop="analyze"> </el-table-column>
        <el-table-column label="操作" fixed="right" width="100">
          <template slot-scope="scope">
            <el-button size="mini" type="text">分析</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.page_num"
        :page-sizes="[10, 20, 40, 80]"
        :page-size="queryInfo.page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 查询条件参数
      queryInfo: {
        task_id: this.$route.query.id,
        result: "",
        // 当前的页数
        page_num: 1,
        // 当前每页显示多少条数据
        page_size: 10,
      },
    // 测试结果列表数据
      testresultList: [],
      total: 0,
    };
  },

  created() {
      this.getTestresultList();
  },

  methods: {
    //  获取测试结果数据
    async getTestresultList() {
        const {data: res} = await this.$http.post(
            "/testresult/list",
        this.qs.stringify(this.queryInfo)
        );
        if(res.code !== 200) {
            return this.$message.error(res.msg);
        }
        for(var i=0; i< res.data.length; i++) {
            res.data[i].duration = this.$common((Number(res.data[i].stop) - Number(res.data[i].start))/1000)
            res.data[i].start = this.$moment(Number(res.data[i].start)).format('YYYY-MM-DD hh:mm:ss')
        }

        this.testresultList = res.data
        this.total = res.count
    },

    // 监听 pageSize 改变的事件
    handleSizeChange(newSize) {
      // console.log(newSize)
      this.queryInfo.page_size = newSize;
      this.getTestresultList();
    },

    // 监听页码值改变的事件
    handleCurrentChange(newPage) {
      // console.log(newPage)
      this.queryInfo.page_num = newPage;
      this.getTestresultList();
    },

    // // 格式化时间
    // formatSeconds: function(value) {
    //   var theTime = parseInt(value); // 需要转换的时间秒
    //   var theTime1 = 0; // 分
    //   var theTime2 = 0; // 小时
    //   var theTime3 = 0; // 天
    //   if (theTime > 60) {
    //     theTime1 = parseInt(theTime / 60);
    //     theTime = parseInt(theTime % 60);
    //     if (theTime1 > 60) {
    //       theTime2 = parseInt(theTime1 / 60);
    //       theTime1 = parseInt(theTime1 % 60);
    //       if (theTime2 > 24) {
    //         //大于24小时
    //         theTime3 = parseInt(theTime2 / 24);
    //         theTime2 = parseInt(theTime2 % 24);
    //       }
    //     }
    //   }
    //   var result = "";
    //   if (theTime == 0) {
    //     result = "1秒";
    //   }
    //   if (theTime > 0) {
    //     result = "" + parseInt(theTime) + "秒";
    //   }
    //   if (theTime1 > 0) {
    //     result = "" + parseInt(theTime1) + "分" + result;
    //   }
    //   if (theTime2 > 0) {
    //     result = "" + parseInt(theTime2) + "小时" + result;
    //   }
    //   if (theTime3 > 0) {
    //     result = "" + parseInt(theTime3) + "天" + result;
    //   }
    //   return result;
    // },
  }
};
</script>

<style lang="less" scoped></style>
